package StudyCode.summary.myfile;

import java.io.IOException;
import java.nio.ByteBuffer;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class DiffByteBuffer {
	public static boolean diff(ByteBuffer b1, ByteBuffer b2)
			throws IOException {
		if (b1 == b2 || b1 != null && b1.equals(b2))
			return false;

		if (b1 == null)
			return b2 != null && b2.remaining() != 0;

		if (b2 == null)
			return b1 != null && b1.remaining() != 0;

		b1 = b1.slice();
		b2 = b2.slice();

		int len = b1.capacity();
		if (len != b2.capacity())
			return true;

		int p = 0;

		for (; p < len - 7; p += 8)
			if (b1.getLong() != b2.getLong())
				return true;

		for (; p < len; p++)
			if (b1.get() != b2.get())
				return true;

		return false;
	}
}
